/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.jm.financeiro.datamodel;

import br.jm.financeiro.entity.Modulo;
import java.io.Serializable;
import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

/**
 *
 * @author joao
 */
public class LazySelectedModulo extends ListDataModel<Modulo> implements SelectableDataModel<Modulo>, Serializable { 
    private static final long serialVersionUID = 8410509299732543629L;

    public LazySelectedModulo() {
        
    }
    
    public LazySelectedModulo(List<Modulo> data) {
        super(data);
    }
    
    @Override
    public Modulo getRowData(String rowKey) {
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data
        
        List<Modulo> modulos = (List<Modulo>) getWrappedData();
        
        for(Modulo modulo : modulos) {
            if(modulo.getIdModulo().toString().equals(rowKey))
                return modulo;
        }
        
        return null;
    }

    @Override
    public Object getRowKey(Modulo modulo) {
        return modulo.getDscModulo();
    }
}
